<html>
<head>
    <meta charset="UTF-8">
    <title>签到</title>
    <script src="js/axios-0.18.0.js"></script>
    <script src="js/jquery-3.1.1.min.js" type="text/javascript"></script>
</head>
<body>

<button id="buttons">签到</button>
<a href="http://localhost:8080/zt12-26/invite.html">查看邀请人信息</a>

<table border="1" width="400">
    <tr>
        <td>id</td>
        <td>电话</td>
        <td>签到时间</td>
        <td>积分</td>
    </tr>
    <tbody id="tbody"></tbody>

</table>

<script>
    // 页面加载完完成
    $(function () {
        $.ajax({
            type: "get",
            url: "http://localhost:8080/zt12-26/list",
            dataType: "json",
            success: function (backData) {
                if (backData.code == 200) {
                    var courses = backData.data;
                    $(courses).each(function () {
                        var html = "<tr></tr><td>" + this.id + "</td>\n" +
                            "        <td>" + this.phone + "</td>\n" +
                            "        <td>" + this.signTime + "</td>\n" +
                            "        <td>" + this.point + "</td>\n";
                        $("#tbody").append($(html))
                    })
                } else if (backData.code == 403) {
                    alert("请登录后访问")
                    window.location.href = "http://localhost:8080/zt12-26/login.html"
                } else {
                    alert(backData.msg);
                }
            },
            error: function () {
                alert("ajax请求异常")
            }
        })
    })


</script>

<script>
    document.getElementById("buttons").onclick = function (){

        //2. 发送ajax请求
        axios({
            method:"get",
            url:"http://localhost:8080/zt12-26/sign",
        }).then(function (resp) {
            //获取数据
            if (resp.data.code == 200){
                window.location.href="http://localhost:8080/zt12-26/sign.html"
            }else {
                alert("签到错误");
            }
        })

    }
</script>

</body>
</html>
